package com.zq.recruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.recruit.dao.entity.Company;
import com.zq.recruit.dao.entity.DeliveryRecord;
import com.zq.recruit.dao.entity.JobPosition;
import com.zq.recruit.service.CompanyService;
import com.zq.recruit.service.DeliveryRecordService;
import com.zq.recruit.mapper.DeliveryRecordMapper;
import com.zq.recruit.service.JobPositionService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 张乔
* @description 针对表【delivery_record(职位投递记录表)】的数据库操作Service实现
* @createDate 2025-04-05 19:14:49
*/
@Service
@Slf4j
public class DeliveryRecordServiceImpl extends ServiceImpl<DeliveryRecordMapper, DeliveryRecord>
    implements DeliveryRecordService{


    @Resource
    private JobPositionService jobPositionService;

    @Resource
    private CompanyService companyService;



    @Override
    public List<JobPosition> getInfoByUserId(Integer userId) {
        LambdaQueryWrapper<DeliveryRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(userId!=null,DeliveryRecord::getUserId,userId);
        List<DeliveryRecord> deliveryRecords = this.list(queryWrapper);
        if(deliveryRecords ==null|| deliveryRecords.isEmpty()){
            return List.of();
        }
        List<JobPosition> list = new ArrayList<>();
        for(DeliveryRecord userCollection:deliveryRecords){
            JobPosition byId = jobPositionService.getById(userCollection.getJobId());
            Company byId1 = companyService.getById(byId.getCompanyId());
            if(byId1!=null){
                byId.setCompanyName(byId1.getCompanyName());
                byId.setCompanyPath(byId1.getImageUrl());
            }
            byId.setFileUrl(userCollection.getResumeUrl());
            list.add(byId);
        }
        return list;
    }

    @Override
    public List<JobPosition> getInfoByJobId(Integer jobId) {
        LambdaQueryWrapper<DeliveryRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(jobId!=null,DeliveryRecord::getJobId,jobId);
        List<DeliveryRecord> deliveryRecords = this.list(queryWrapper);
        if(deliveryRecords ==null|| deliveryRecords.isEmpty()){
            return List.of();
        }
        return List.of();
    }

    @Override
    public List<JobPosition> getAllInfoByJob() {
        List<DeliveryRecord> deliveryRecords = this.list();
        if(deliveryRecords ==null|| deliveryRecords.isEmpty()){
            return List.of();
        }
        List<JobPosition> list = new ArrayList<>();
        for(DeliveryRecord userCollection:deliveryRecords){
            JobPosition byId = jobPositionService.getById(userCollection.getJobId());
            Company byId1 = companyService.getById(byId.getCompanyId());
            if(byId1!=null){
                byId.setCompanyName(byId1.getCompanyName());
                byId.setCompanyPath(byId1.getImageUrl());
            }
            byId.setFileUrl(userCollection.getResumeUrl());
          byId.setDeliveryRecordId(userCollection.getDeliveryId());
            list.add(byId);
        }
        return list;
    }



}




